stylecontext: Separate properties by states
authorBenjamin Otte <otte@redhat.com>
Tue, 27 Dec 2011 19:41:25 +0000 (20:41 +0100)
committerBenjamin Otte <otte@redhat.com>
Mon, 9 Jan 2012 17:37:49 +0000 (18:37 +0100)
We don't want to mix states the wrong way. And the current approach does
that.

gtk/gtkstylecontext.c

index eaff91bcccc67bc9595ad66e840c641299046d0e..d4f909a8189677b7f7a546f7b08a975590c54228 100644 (file)
@@ -513,7 +513,7 @@ style_info_hash (gconstpointer elem)
       hash <<= 5;
     }
 
-  return hash;
+  return hash ^ info->state_flags;
 }
 
 static gboolean
@@ -525,6 +525,9 @@ style_info_equal (gconstpointer elem1,
   info1 = elem1;
   info2 = elem2;
 
+  if (info1->state_flags != info2->state_flags)
+    return FALSE;
+
   if (info1->junction_sides != info2->junction_sides)
     return FALSE;
 
@@ -1015,15 +1018,23 @@ style_data_lookup (GtkStyleContext *context,
 {
   GtkStyleContextPrivate *priv;
   StyleData *data;
+  gboolean state_mismatch;
 
   priv = context->priv;
+  state_mismatch = ((GtkStyleInfo *) priv->info_stack->data)->state_flags != state;
 
   /* Current data in use is cached, just return it */
-  if (priv->current_data)
+  if (priv->current_data && !state_mismatch)
     return priv->current_data;
 
   g_assert (priv->widget_path != NULL);
 
+  if (G_UNLIKELY (state_mismatch))
+    {
+      gtk_style_context_save (context);
+      gtk_style_context_set_state (context, state);
+    }
+
   data = g_hash_table_lookup (priv->style_data, priv->info_stack->data);
 
   if (!data)
@@ -1043,17 +1054,25 @@ style_data_lookup (GtkStyleContext *context,
       gtk_widget_path_free (path);
     }
 
-  priv->current_data = data;
+  if (G_UNLIKELY (state_mismatch))
+    {
+      gtk_style_context_restore (context);
+      priv->current_data = NULL;
+    }
+  else
+    {
+      priv->current_data = data;
 
-  if (priv->theming_engine)
-    g_object_unref (priv->theming_engine);
+      if (priv->theming_engine)
+        g_object_unref (priv->theming_engine);
 
-  gtk_style_properties_get (data->store, 0,
-                            "engine", &priv->theming_engine,
-                            NULL);
+      gtk_style_properties_get (data->store, 0,
+                                "engine", &priv->theming_engine,
+                                NULL);
 
-  if (!priv->theming_engine)
-    priv->theming_engine = g_object_ref (gtk_theming_engine_load (NULL));
+      if (!priv->theming_engine)
+        priv->theming_engine = g_object_ref (gtk_theming_engine_load (NULL));
+    }
 
   return data;
 }